<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <%@include file="../../../../resources/inc/head.jsp" %>
</head>
<body>
<style>
    .layui-inline{
        width: 200px;
    }
</style>
<div class="layui-fluid">

    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto option-bar">
            <div class="layui-collapse ">
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">展开搜索</h2>
                     <div class="layui-colla-content">
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span class="require-field"></span>发起时间 </label>

                            <div class="layui-inline">

                                <input type="text" id="startTime1" name="startTime1" placeholder="开始时间" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-inline">

                                <input type="text" id="endTime1" name="endTime1" placeholder="结束时间" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                         <div class="layui-form-item">
                             <label class="layui-form-label"><span class="require-field"></span>完成时间 </label>

                             <div class="layui-inline">
                                 <input type="text" id="startTime2" name="startTime2" placeholder="开始时间" autocomplete="off" class="layui-input">
                             </div>
                             <div class="layui-inline">
                                 <input type="text" id="endTime2" name="endTime2" placeholder="结束时间" autocomplete="off" class="layui-input">
                             </div>
                         </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span class="require-field"></span> </label>
                            <div class="layui-inline">
                                <input type="text" id="orderId11" name="orderId" placeholder="支付订单号" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-inline">
                                <input type="text"  name="tradeNo" placeholder="通道订单号" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-inline">
                                <input type="text"  name="merchantOrderId" placeholder="商户订单号" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-inline">
                                <input type="text"  name="grandTotal" placeholder="订单金额" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                         <div class="layui-form-item">
                             <label class="layui-form-label"><span class="require-field"></span> </label>
                             <div class="layui-inline">

                             <select  name="paymentChannel" placeholder="通道类型">
                                 <option value="">选择通道类型</option>

                                 <c:forEach items="${paymentChannels}" var="paymentChannel">
                                        <option value="${paymentChannel.id}">${paymentChannel.name}</option>
                                    </c:forEach>
                                </select>
                             </div>

<%--                                 <div class="layui-inline">--%>
<%--                                 <expect-x:dictSelect field="state" typeGroupCode="state_type" placeholder="通道类型"--%>
<%--                                                      defaultVal="" />                             </div>--%>
                             <c:if test="${orderType==null}">
                                 <div class="layui-inline">
                                     <expect-x:dictSelect field="orderType1" typeGroupCode="order_type" placeholder="交易类型"
                                                             verify="false"/>
                                 </div>
                             </c:if>
                             <div class="layui-inline">
                                 <select  name="merchantApplication" placeholder="对应app">
                                     <option value="">选择对应app</option>
                                     <c:forEach items="${merchantApplications}" var="merchantApplication">
                                         <option value="${merchantApplication.id}">${merchantApplication.name}</option>
                                     </c:forEach>
                                 </select>
                             </div>
<%--                             <div class="layui-inline">--%>
<%--                                 <expect-x:dictSelect field="state" typeGroupCode="state_type" placeholder="所属应用"--%>
<%--                                                      defaultVal="" />--%>
<%--                             </div>--%>
                             <div class="layui-inline">
                                 <expect-x:dictSelect field="payStatus" typeGroupCode="state_type" placeholder="状态"
                                                      verify="false" />
                             </div>
                             <div class="layui-inline">
                                 <button  class="layui-btn" lay-submit lay-filter="Type-serch">
                                     搜索
                                 </button>
                             </div>

                         </div>

                    </div>

                </div>
            </div>

        </div>


        <div class="layui-card-body">


                <div class="layui-row">
<%--                    <span class="layui-inline"id="total">--%>
<%--                    </span>--%>
<%--                    <span class="layui-inline"id="sum">--%>
<%--                    </span>--%>
<%--                    <span class="layui-inline"id="serviceFee">--%>
<%--                    </span>--%>
<%--                    <span class="layui-inline"id="money">--%>
<%--                    </span>--%>
                </div>

            <table id="productBrandManage" lay-filter="productBrandManage"></table>
            <script type="text/html" id="optionToolbar">
                <form  enctype="multipart/form-data">
                    <c:if test="${orderType==null}">
<div   class="layui-inline">  <span class="layui-badge"id="total">
                    </span></div>
                        <div   class="layui-inline"> <span class="layui-badge layui-bg-orange"id="sum">
                    </span></div>
                        <div   class="layui-inline">  <span class="layui-badge layui-bg-green"id="serviceFee">
                    </span></div>
                        <div   class="layui-inline">  <span class="layui-badge layui-bg-cyan"id="money">
                    </span></div>
                    </c:if>
                </form>
            </script>
            <script type="text/html" id="optionBar">
            <%--<shiro:hasPermission name="Expect-X:product:product:update">--%>
            <a class="layui-btn  layui-btn-warm layui-btn-xs" lay-event="orderDetails">订单详情</a>
            </script>
            <script type="text/javascript" >
                function exportExcel() {
                    var orderId =   $('#orderId1').val();
                    var productName =   $('#productName1').val();
                    var orderDate =   $('#orderDate1').val();
                    var txt= {
                        "orderId":orderId,
                        "productName":productName,
                        "orderDate":orderDate};
                    var json= JSON.stringify(txt);
                    window.location.href = "<%=basePath%>/manager/product/orderHeader/export/"+json+".html";
                }
            </script>
            <script type="text/html" id="gmtModifiedTpl">
                {{#
                var date = new Date();
                date.setTime(d.gmtModified);
                return date.Format("yyyy-MM-dd hh:mm:ss");
                }}
            </script>
            <script type="text/html" id="orderStatus">

                <%--{{#  if(d.orderStatus==1){ }}--%>
                <%--<span class="layui-badge">待支付</span>--%>
                <%--{{#  } else if(d.orderStatus ==2) { }}--%>
                <%--<span class="layui-badge layui-bg-green">支付成功</span>--%>
                <%--{{#  } else if(d.orderStatus ==3) { }}--%>
                <%--<span class="layui-badge layui-bg-orange">支付失败</span>--%>
                <%--{{#  } else  if(d.orderStatus ==4){ }}--%>
                <%--<span class="layui-badge layui-bg-green">退款中</span>--%>
                <%--{{#  } else  if(d.orderStatus ==5){ }}--%>
                <%--<span class="layui-badge layui-bg-green">退款成功</span>--%>
                <%--{{#  }}}--%>

                {{#  if(d.orderStatus==0){ }}
                <span class="layui-badge">待付款</span>
                {{#  } else if(d.orderStatus ==1) { }}
                <span class="layui-badge layui-bg-green">已支付</span>
                {{#  } else if(d.orderStatus ==2) { }}
                <span class="layui-badge layui-bg-orange">支付失败</span>
                {{#  }}}
            </script>
            <script type="text/html" id="orderType2">
            {{
            d.orderType==1?'抢购':d.orderType==2?'零售':'折扣'
            }}
            </script>
            <script type="text/html" id="isDisabledTpl">
                <input type="checkbox" name="state" value="{{d.id}}" title="禁用" lay-filter="isDisabledFilter" {{
                       d.sta te==1?'checked':''}}>
            </script>
            <script type="text/html" id="productImg">

                <div><img src="{{d.productImg==null?'<%=basePath%>resources/images/noImage.jpg':d.productImg}}" style="height: 28px" class="layui-table-link"></div>
            </script>
            <script type="text/html" id="channelPaywayName">
                <c:forEach  items="${paymentChannels}" var="channel">
                    {{#  if(d.channelId==${channel.id}){ }}
                        ${channel.name}
                    {{#  }}}
                </c:forEach>
            </script>
            <script type="text/html" id="money1">
                <b style="color: red">￥{{d.grandTotal-d.serviceFee}}</b>
            </script>
            <script type="text/html" id="productCategory">
                {{d.productCategory==null?'':d.productCategory.productCategoryName}}
            </script>
            <script type="text/html" id="productPriceTpl">
                <b style="color: red">￥{{d.grandTotal}}</b>
            </script>

            <script type="text/html" id="receivingPhone">
                {{d.receivingPhone==null?'':d.receivingPhone}}
            </script>
            <script type="text/html" id="receivingAddress">
                {{d.receivingAddress==null?'':d.receivingAddress}}
            </script>
            <script type="text/html" id="currencyUom">
                {{d.currencyUom==null?'':d.currencyUom}}
            </script>
            <script type="text/html" id="servicefee1">
                {{d.servicefee==null?'<b style="color: red">￥0</b>':d.servicefee}}
            </script>
        </div>
    </div>
</div>

<%@include file="../../../../resources/inc/footer.jsp" %>
<script>
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['laydate','index', 'table'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table,
            laydate = layui.laydate;
        laydate.render({
            elem: '#startTime1' //指定元素
        });
        laydate.render({
            elem: '#startTime2' //指定元素
        });
        laydate.render({
            elem: '#endTime1' //指定元素
        });
        laydate.render({
            elem: '#endTime2' //指定元素
        });
        var orderStatus="${orderStatus}"
        var todayOrder="${todayOrder}"
        var orderType="${orderType}"
        table.render({
            elem: '#productBrandManage',
            url: '<%=basePath%>manager/product/orderHeader/page.html?orderType='+orderType+'&&todayOrder='+todayOrder,
            toolbar: '#optionToolbar',
            cols: [[
                {type: 'checkbox',fixed:'left'}
                , {field: 'orderId', width: 230, title: '订单号', sort: true}
                , {field: 'orderName',width: 170,title: '订单名称' }
                , {field: 'orderDate',width: 160,title: '下单日期' ,templet: "#gmtModifiedTpl"}
                , {field: 'channelPaywayName',width: 170,title: '支付通道',templet: "#channelPaywayName"}
                , {title: '订单状态 ',width: 90,templet: "#orderStatus"}
                , {field: 'grandTotal',width: 90,title: '订单总额',templet: "#productPriceTpl" }
                , {field: 'currencyUom',title: '币种 ',templet: "#currencyUom"}
                , {field: 'servicefee',width: 90,title: '手续费 ',templet: "#servicefee1"}
                , {title: '结算金额 ', width: 90,templet: "#money1"}
                , {field: 'gmtModified', width:160,title: '更新时间', sort: true, templet: "#gmtModifiedTpl"}
                , {title: "操作", width: 150, align: "center", fixed: "right", toolbar: "#optionBar"}

            ]],
            page: !0,
            limit: 10,
            height: "full-130",
            text: {none:"暂无可显示数据"},
            response: {
                statusCode: 200
            },
            done: function(res, curr, count){
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                console.log(res);
                $("#total").html('总笔数:  '+(res.count)+"笔")
                $("#sum").html('总金额: '+res.sumMoney+"元")
                $("#serviceFee").html('手续费: '+res.serviceFee+"元")
                $("#money").html('结算金额: '+(res.settlementTotal)+"元")
                // alert(res.sumMoney)
                //得到当前页码
                console.log(curr);

                //得到数据总量
                console.log(count);
            }

        });
        laydate.render({
            elem: '#date1' //指定元素
        });
        //监听单元格编辑
        table.on('edit(productBrandManage)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            $.ajax({
                url:"<%=basePath%>manager/product/product/changeField.html",
                type:"get",
                data:{id:data.id,name:obj.value},
                success:function (data) {

                    layer.closeAll('loading');
                    data=JSON.parse(data);

                    if(data.success){
                        table.reload('productBrandManage');
                        layer.close(index);
                    }else{
                        layer.msg(data.message);
                    }
                }
            });
        });
        table.on('toolbar(productBrandManage)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    var diglog=new UtilClass.LayerDialog({
                        title: '添加商品'
                        ,content: '<%=basePath%>manager/product/product/create.html'
                    });
                    diglog.layerShow();
                    break;
                case 'dels':
                    var data = checkStatus.data;
                    var List=JSON.stringify(data);
                    var jsList =JSON.parse(List);
                    if(jsList[0]==null){
                        layer.msg('请选中至少一行');
                    }else{
                    var chars=new Array();
                    for(var  li in jsList){
                        chars[li]=jsList[li].id;
                    }
                    var str="";
                    for( var i=0;i<chars.length;i++){
                    if(i==chars.length-1){
                        str+=chars[i];
                    }
                    else{str=str+chars[i]+",";
                    }
                }
                       layer.load(2);
                    $.ajax({
                        type: "get",
                        url: "<%=basePath%>manager/product/product/delete/"+str+".html",
                        success: function(data) {
                             layer.closeAll("loading");
                           data=JSON.parse(data);


                        if(data.success){
                            layer.msg("删除成功");
                                table.reload('productBrandManage');

                            }else{
                                layer.msg(data.message, {icon: 5});
                            }
                        }
                    });
                    break;}
            };
        });
        table.on("tool(productBrandManage)", function (e){
            console.log(e.data);
            if ("del" === e.event){
                layer.confirm("真的删除行么", function (t) {
                    layer.close(t);

                    var List=JSON.stringify(e.data);
                    var jsList =JSON.parse(List);
                    var ids=jsList.id;
                    layer.load(2);
                    $.ajax({
                        type: "get",
                        url: "<%=basePath%>manager/product/product/delete/"+ids+".html",
                        success: function(data) {
                             layer.closeAll("loading");
                            data=JSON.parse(data);


                            if(data.success){
                                table.reload('productBrandManage');

                            }else{
                                layer.msg(data.message, {icon: 5});
                            }
                        }
                    });

                })
            }else if ("edit" === e.event) {
                var diglog=new UtilClass.LayerDialog({
                    title: "编辑["+e.data.productName+"]",
                    content: "<%=basePath%>manager/product/product/update/"+e.data.id+".html",
                });
                diglog.layerShow();
                $(e.tr);

            }else if('pay' === e.event){
                $.ajax({
                    type: "get",
                    data:{keyword:e.data.orderId},
                    url: "<%=basePath%>util/Aes.html",
                    success: function(data) {
                        window.open('http://192.168.2.103:1111/pay/pay.html?orderId='+data+'')

                    }
                });
            }else if('orderDetails' === e.event){
                layer.open({
                    type: 2,
                    title: "订单详情",
                    content: "<%=basePath%>manager/product/orderHeader/orderDetails/" + e.data.orderId + ".html",
                    maxmin: !0,
                    area: ["100%", "100%"],
                });
            }
        });


        //监听搜索
        form.on('submit(Type-serch)', function (data) {
            var field = data.field;
            $(".layui-laypage-skip").find("input").val("1");
            $(".layui-laypage-btn").click();
            table.reload('productBrandManage', {
                where: field
            });
        });




    });
    function edit(e) {

    }

</script>
</body>
</html>

